package com.spzx.channel.service.impl;

import com.spzx.channel.service.IIndexService;
import com.spzx.common.core.constant.SecurityConstants;
import com.spzx.common.core.domain.R;
import com.spzx.product.api.RemoteCategoryService;
import com.spzx.product.api.RemoteProductService;
import com.spzx.product.api.domain.CategoryVo;
import com.spzx.product.api.domain.ProductSku;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author ChenXing
 * @Description
 * @Create 2024/8/7 18:43
 */

@Service
public class IndexServiceImpl implements IIndexService {


    @Autowired
    private RemoteProductService remoteProductService;

    @Autowired
    private RemoteCategoryService remoteCategoryService;

//    @Autowired
//    private SpzxService spzxService;



    @Override
    public Map<String, Object> getindexData() {

     // 实现类中，这儿真正调用远程接口

     // 查询一级分类
        R<List<CategoryVo>> categoryList =  remoteCategoryService.getOneCategory(SecurityConstants.INNER);

     // 查询商品列表
        R<List<ProductSku>> productSkuList = remoteProductService.getTopSale(SecurityConstants.INNER);


        // 封装 map
        Map<String,Object> map = new HashMap<>();

        // 因为被 R 封装，所以要 getData 一下
        map.put("categoryList",categoryList.getData());
        map.put("productSkuList",productSkuList.getData());

        return map;
    }
}
